<template>
  <div class="produce-list-start" id="produceListStart">
    <div class="container">

      <createTop firstMenu="订单管理" secondMenu="生产单" title="生产单"></createTop>

      <el-button
      size="small"
      plain
      type="info"
      class="daochu-btn"
      @click="$getPdf('#produceListStart','生产单')">导出PDF</el-button>

      <!-- 第一个表格 -->
      <el-card class="first">
        <div class="first-title">
          <div class="left big-wrod">{{status}}</div>
          <div class="right">
            <div class="right-top">
              <div><span class="big">生产单号: </span>{{info.sc_order}}</div>
              <div><span class="big">销售员: </span>{{info.sell_username}}</div>
              <div><span class="big">交货日期: </span>{{info.date}}</div>
            </div>
            <div class="right-bottom">
              <div><span class="big">订单号: </span>{{info.order}}</div>
            </div>
          </div>
        </div>
      
        <el-table
        :border="true"
        :data="row"
        style="width: 100%"
        :fit="true"
        :stripe="true"
        size="mini"
        align="center">


          <el-table-column
            prop="goods_number"
            label="商品编号"
            min-width="100"
            align="center">
          </el-table-column>

          <el-table-column
            prop="goods_name"
            label="商品名称"
            min-width="130"
            align="center">
          </el-table-column>

          <el-table-column
            prop="class_name"
            label="类别"
            min-width="130"
            align="center">
          </el-table-column>

          <el-table-column
            prop="goods_model"
            label="型号"
            min-width="120"
            align="center">
          </el-table-column>

          <el-table-column
            prop="count"
            label="数量"
            min-width="120"
            align="center">
          </el-table-column>

        </el-table>
        </el-card>


      <!-- 第二个表格 -->
      <el-card class="top-card" shadow="always">
        <div slot="header" class="card-title">
          <span>配料清单</span>
        </div>
           <div class="produce-list-start-table-wrap">
              <el-table
                :data="materials"
                style="width: 100%"
                :fit="true"
                :stripe="true"
                size="mini"
                :border="true"
                align="center">

                <el-table-column
                  prop="format_id"
                  label="id"
                  min-width="100"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="material_number"
                  label="配料编号"
                  min-width="100"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="material_name"
                  label="配料名称"
                  min-width="130"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="format_name"
                  label="规格/型号"
                  min-width="130"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="material_unit"
                  label="单位"
                  min-width="120"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="need_count"
                  label="配料需量"
                  min-width="120"
                  align="center">
                </el-table-column>
                
                <el-table-column 
                prop="out_count"
                label="出库数量"
                min-width="180"
                align="center">
                  <template slot-scope="scope">
                    <div>{{scope.row.out_count.replace('-','')}}</div>
                  </template>
                </el-table-column>

                <el-table-column 
                prop="remarks"
                label="备注"
                min-width="180"
                align="center">
                </el-table-column>
              </el-table>
            </div>
      </el-card>

      <el-button
      v-if="status==='开始生产'"
      size="small"
      type="primary"
      @click="finishProduce">生产完成</el-button>

      <el-button
      v-if="status==='生产完成'"
      size="small"
      type="primary"
      @click="inStock">入 库</el-button>

      <el-dialog
        v-if="showDone"
        title=""
        :visible="true"
        center
        width="350px"
        :show-close="false">
        <div :style="{'textAlign':'center'}">确认已生产完成?</div>
        <span slot="footer" class="dialog-footer">
          <el-button plain type="primary" @click="showDone = false">取 消</el-button>
          <el-button type="primary" @click="secondConfirm">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog v-if="inStockDialog" title="提示" center width="400px" :visible="true" @close="close">
        <div :style="{'textAlign':'center'}">商品数量{{number}}</div>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="inStockConfirm">确 定</el-button>
          </span>
      </el-dialog>

    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import createTop from '@/components/createTop.vue';
import saveBtn from '@/components/saveBtn.vue';
import ajaxResquest from '@/api/apiRequest';
import childTable from '@/tables/order/productListWaitChild.vue';
@Component({
  components: {
    createTop,
    saveBtn,
    childTable
  }
})
export default class ProductListWait extends Vue {
  createRes!: ajaxResquest;
  infoRes!: ajaxResquest;
  finishRes!: ajaxResquest;
  inStockRes!: ajaxResquest;
  row: any = [];

  $router!: any;
  id: any = '';
  status: string = '';
  materials: any[] = [];
  info: any = {};
  inStockDialog: boolean = false;
  number!: number;
  showDone: boolean = false;
  mounted() {
    // this.row = temp;
    this.id = this.$route.query.id;
    this.status = this.$route.query.status;
    console.log(this.status);

    let infoUrl: string = '';
    if (this.status === '开始生产') {
      infoUrl = '/order/startProductions';
    } else if (this.status === '生产完成') {
      infoUrl = 'order/finishProductionsInfo';
    } else if (this.status === '已入库') {
      infoUrl = '/order/productionsInInfo';
    }
    this.infoRes = new ajaxResquest(infoUrl);
    this.createRes = new ajaxResquest('/goods/addGoodsOut');
    this.finishRes = new ajaxResquest('/order/finishProductions');
    this.inStockRes = new ajaxResquest('/order/getGoodsNumber');

    this.getInfo();
  }
  getInfo() {
    this.infoRes.getFunction({ orderId: this.id }).then((res: any) => {
      let temp: any[] = [res.data.data.types.goods];
      this.row = temp;
      this.materials = res.data.data.types.materials;
      // this.materials.map((i:any)=>{
      //   i.out_count.repla
      // })
      this.info = res.data.data.types.orderInfo;
    });
  }
  // 生产完成按钮
  finishProduce() {
    this.showDone = true;
  }
  secondConfirm() {
    this.finishRes.getFunction({ orderId: this.id }).then((res: any) => {
      if (res.data.code === 1) {
        console.log(res.data.data);
        this.showDone = false;
        this.$to('productList');
      }
    });
  }
  close() {
    this.inStockDialog = false;
  }
  inStock() {
    console.log(this.row);
    this.$to('toStroke', { row: this.row, id: this.id });
  }
}
</script>
<style lang="less">
.produce-list-start {
  height: 100%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  // z-index: 101;
  box-sizing: border-box;
  overflow-y: auto;
  text-align: left;
  .top-card {
    // padding: 10px;
    box-sizing: border-box;
    margin-bottom: 15px;
  }
  .el-card {
    overflow-y: auto;
  }
  .content {
    // display: flex;
    // flex-direction: column;
    font-size: 16px;
    background-color: #fff;
    border-radius: 4px;
    .content-title {
      height: 40px;
      margin-top: 20px;
      line-height: 2;
      text-align: left;
    }
    .short-input {
      width: 100%;
      width: 240px;
      margin-right: 10px;
    }
    .el-upload-list__item {
      width: 350px;
    }
    .el-textarea {
      margin-bottom: 30px;
    }
  }
  .card-title {
    text-align: left;
    font-weight: 600;
  }
  .first {
    margin-bottom: 15px;
    text-align: left;
    // display: flex;
    // flex-direction: row;
    .first-title {
      display: flex;
      margin-bottom: 20px;
    }
    .left {
      margin-right: 40px;
      // float: left;
      // height: 100%;
    }
    .big-wrod {
      font-size: 24px;
      color: red;
    }
    .right {
      font-size: 14px;
      div {
        min-width: 140px;
        margin-right: 10px;
      }
      .big {
        font-weight: 600;
      }
    }
    .right-top {
      display: flex;
      margin-bottom: 10px;
    }
  }
}
</style>
